package produce;

public class ThreadConsumer extends Thread{//消费者继承父类

    //属性
    private MyStack stack;

    public ThreadConsumer(MyStack stack){

        this.stack = stack;
    }

    //行为
    public  void  run(){
        //通过重写run方法达到多线程的业务逻辑处理的目的
        while (true){
            System.out.println("消费者消费了一个产品，进行出栈操作");
            //入栈
            Object object = stack.pop();
            if (object == null){
                System.out.println("消费者没有消费到商品");
            }
            //休眠1秒
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
